using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;

namespace Patterns.Tools.CodeGenerators.GoogleCode.Assemblies
{
	public sealed class AssemblyModel : WikiFolderModel
	{
		private int _baseIndentLevel;

		public AssemblyModel(Assembly assembly)
		{
			TargetType = "assembly";
			Namespaces = Enumerable.Empty<string>();
		}

		public override void Initialize()
		{
			Summary = string.Format("the {0} assembly (version {1})", Target, Version);
			_baseIndentLevel = Namespaces.Select(NumberOf.Dots).Min();
		}

		public string Version { get; set; }
		public string Description { get; set; }
		public IEnumerable<string> Namespaces { get; set; }

		public IDictionary<string,string> GetNamespaceLinks()
		{
			return Namespaces.OrderBy(item => item)
				.ToDictionary(item => item, item => GetWikiUri(WikiNames.Namespace(item)));
		}

		public string Indent(string namespaceName)
		{
			return new string(' ', (NumberOf.Dots(namespaceName) - _baseIndentLevel) * 2);
		}
	}
}